<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
信息来源
<select name="sourceId">
    <OPTION value="">请选择</OPTION>
    <c:forEach items="${sourceList}" var="s">
        <option value="${s.id}">${s.name}</option>
    </c:forEach>
</select><br>
人员状态
<input name="status"><br>


<button onclick="zxt()">点击展示折线图</button>
<button onclick="zzt()">点击展示柱状图</button>
<button onclick="bing()">点击展示饼状图</button>
<button onclick="excel()">点击导出Excel</button>

<div id="main" style="width: 800px;height: 500px">

</div>


</body>


<script>

    function excel() {
        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();
        location.href='excel.do?sourceId=' + sourceId + '&status=' + status
    }


    function bing() {
        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();

        $.ajax({
            url: '/bing.do?sourceId=' + sourceId + '&status=' + status,
            success: function (res) {

                console.log(res)

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                const piePatternSrc =
                    '';
                const bgPatternSrc =
                    '';
                const piePatternImg = new Image();
                piePatternImg.src = piePatternSrc;
                const bgPatternImg = new Image();
                bgPatternImg.src = bgPatternSrc;
                option = {
                    backgroundColor: {
                        image: bgPatternImg,
                        repeat: 'repeat'
                    },
                    title: {
                        text: '饼图纹理',
                        textStyle: {
                            color: '#942385'
                        }
                    },
                    tooltip: {},
                    series: [
                        {
                            name: 'pie',
                            type: 'pie',
                            selectedMode: 'single',
                            selectedOffset: 30,
                            clockwise: true,
                            label: {
                                fontSize: 18,
                                color: '#942385'
                            },
                            labelLine: {
                                lineStyle: {
                                    color: '#942385'
                                }
                            },
                            data: res,
                            itemStyle: {
                                opacity: 0.7,
                                color: {
                                    image: piePatternImg,
                                    repeat: 'repeat'
                                },
                                borderWidth: 3,
                                borderColor: '#942385'
                            }
                        }
                    ]
                };

                option && myChart.setOption(option);

            }
        })

    }




    function zzt() {

        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();

        $.ajax({

            url: '/zxt.do?sourceId=' + sourceId + '&status=' + status,
            success: function (res) {
                console.log(res)

                var x = []
                var y = []

                for (let i = 0; i < res.length; i++) {
                    let xdata = res[i].xdata;
                    let ydata = res[i].ydata;
                    x.push(xdata)
                    y.push(ydata)
                }


                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'bar',
                            showBackground: true,
                            backgroundStyle: {
                                color: 'rgba(180, 180, 180, 0.2)'
                            }
                        }
                    ]
                };

                option && myChart.setOption(option);


            }

        })



    }


    function zxt() {

        let sourceId = $('[name=sourceId]').val();
        let status = $('[name=status]').val();

        $.ajax({

            url: '/zxt.do?sourceId=' + sourceId + '&status=' + status,
            success: function (res) {
                console.log(res)

                var x = []
                var y = []

                for (let i = 0; i < res.length; i++) {
                    let xdata = res[i].xdata;
                    let ydata = res[i].ydata;
                    x.push(xdata)
                    y.push(ydata)
                }

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'line',
                            areaStyle: {}
                        }
                    ]
                };

                option && myChart.setOption(option);


            }

        })


    }


</script>
</html>